﻿using BaseUtils;
using BaseUtils.Helper;
using BaseUtils.Logger;
using BaseUtils.Utils;
using Service.src.NW.Model;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Service.src.Flow.Api
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class SystemApi
    {
        //public string SelectFile()
        //{
        //    OpenFileDialog openFileDialog = new OpenFileDialog();
        //    openFileDialog.InitialDirectory = "c:\\"; // 设置初始目录
        //    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; // 设置文件过滤器
        //    openFileDialog.FilterIndex = 2;
        //    openFileDialog.RestoreDirectory = true;
        //    string filePath = null;
        //    if (openFileDialog.ShowDialog() == DialogResult.OK) // 显示打开文件对话框
        //    {
        //        // 获取选中文件的路径
        //        filePath = openFileDialog.FileName;
        //    }
        //    return filePath;
        //}

        //public void OpenFile(string Path, string FileName)
        //{
        //    try
        //    {
        //        if (string.IsNullOrEmpty(Path))
        //        {
        //            Path = AppDomain.CurrentDomain.BaseDirectory;
        //        }
        //        Process.Start(new ProcessStartInfo
        //        {
        //            FileName = Path + FileName,
        //            UseShellExecute = true
        //        });
        //    }
        //    catch (Exception ex)
        //    {
        //        LoggerService.Error($"文件打开失败，地址{Path + FileName}，原因：{ex.Message}", ex);
        //    }
        //}

        //public void OpenForm(string Uri)
        //{
        //    bool IsOpen = true;
        //    foreach (Form item in Application.OpenForms)
        //    {
        //        if (item is NWUIGeneratorForm GUI && GUI.ViewHandler.uri == Uri)
        //        {
        //            IsOpen = false;
        //            break;
        //        }
        //    }
        //    if (IsOpen)
        //    {
        //        string r = BaseService.AppConfig.field.SupplierName == "NWP" ? "file://" + AppData.AppPath + "dist/index.html#/" : $"http://localhost:5173/#/404";
        //        NWUIGeneratorForm Generator = new NWUIGeneratorForm(Uri);
        //        Generator.Show();
        //    }
        //}

        //public void OpenDialogForm(string Uri)
        //{
        //    NWUIGeneratorForm Generator = new NWUIGeneratorForm(Uri);
        //    Generator.ShowDialog();
        //}

        public string GetSystemConfig()
        {
            return BaseService.AppConfig.ToJson();
        }

        public bool Ping(string IP)
        {
            return CommonUtil.PingTry(IP);
        }
    }
}
